package demo.restful;

import javax.ws.rs.*;

/**
 * Created by IntelliJ IDEA.
 * User: jinshengyuan
 * Date: 2019-02-22
 * Time: 11:32
 * description:
 **/
/*
public class CategoryService {
    @Path("/categoryservice")
    @Produces("application/xml")

}
*/
@Path("/categoryService")
@Produces("application/xml")
public class CategoryService {

    /*public CategoryDAO getCategoryDAO() {
        return categoryDAO;
    }
    //Wired using Spring
    public void setCategoryDAO(CategoryDAO categoryDAO) {
        this.categoryDAO = categoryDAO;
    }*/
   private CategoryDao categoryDao = new CategoryDao();

    public CategoryDao getCategoryDao() {
        return categoryDao;
    }

    public void setCategoryDao(CategoryDao categoryDao) {
        this.categoryDao = categoryDao;
    }

    @GET
    @Path("/category/{id}")
    public Category getCategory(@PathParam("id") String id) {
        return categoryDao.getCategory(id);
    }

    @POST
    @Path("/category")
    @Consumes("application/xml")
    public void addCategory(Category category) {
        categoryDao.addCategory(category);
    }

    @DELETE
    @Path("/category/{id}")
    public void deleteCategory(@PathParam("id") String id) {
        categoryDao.deleteCategory(id);
    }

    @PUT
    @Path("/category")
    public void updateCategory(Category category) {
        categoryDao.updateCategory(category);
    }

    @POST
    @Path("/category/book")
    @Consumes("application/xml")
    public void addBooks(Category category) {
        categoryDao.addBook(category);
    }

    @GET
    @Path("/category/{id}/books")
    @Consumes("application/xml")
    public void getBooks(@PathParam("id") String id) {
        categoryDao.getBooks(id);
    }
}